Skip to content

Conversation

Sokario
Copy link
Contributor

@Sokario Sokario commented Oct 16, 2025

Some sensors have one trigger type for different data.
To address this feature, the standard api sample_fetch/channel_get allows the user to specify channels with the trigger type.
However, the async API Read and Decode doesn't gives channels configuration oportunity.

Proposition:
This issue can be handled by adding enum sensor_channel chan in struct sensor_stream_trigger.
Adding it to the end of the structure doesn't break any macro or existing code.
It allows the user to configure different opt for different channels using the same trigger type.

Implications:
While the default value {0, 0} for chan_spec is not an issue in itself, it becomes problematic when developers start checking for chan_spec in the stream API.

A reworked SENSOR_DT_STREAM_IODEV macro addresses this issue.
In this new design, the macro now handles an array of tuples of size 2 or 3 — (T, O) or (T, O, {C, I}) — instead of the previous array format {T, O} or {T, O, {C, I}}.

This approach enables the use of FOR_EACH_NONEMPTY_TERM in tandem with the newly introduced SENSOR_CHAN_SPEC_PREP, which prepares the construction of the struct sensor_stream_trigger.

Consistency
The struct sensor_chan_spec has been updated for consistency with the struct sensor_stream_trigger.

@Sokario
Copy link
Contributor Author

Sokario commented Oct 20, 2025

@kartben The CI encountered an API rate limit error. I’m not sure if there’s anything I need to do. Is this an issue on Zephyr’s end or on my organization’s end?

@Sokario
Copy link
Contributor Author

Sokario commented Oct 20, 2025

Thanks @kartben for your quick action on this — much appreciated.

@alexapostolu
Copy link
Contributor

alexapostolu commented Oct 20, 2025

Should it be sensor_chan_spec instead of sensor_channel for more generality?

@Sokario
Copy link
Contributor Author

Sokario commented Oct 21, 2025

Oh, you’re right, @alexapostolu — I didn’t think about the channel indices. I’ll make the change.

@Sokario Sokario force-pushed the drivers/sensors/sensor_async branch from fec73ac to a4f510a Compare October 21, 2025 08:55
Added `struct sensor_chan_spec chan_spec` in `struct sensor_stream_trigger`
in order to allow the user to configure different `opt` to different
channels using the same `trigger`.

Signed-off-by: Logan Saint-Germain <[email protected]>
The zero fill of the new struct sensor_stream_trigger make default channel
into `SENSOR_CHAN_ACCEL_X`. Reworked macro instanciation for
sensor_stream_trigger to construct structure with fall back to default
SENSOR_CHAN_ALL. It changes `{}` to `()` in order to use
`FOR_EACH_NONEMPTY_TERM` macro.
Also changed every sample using it and documentation.

Signed-off-by: Logan Saint-Germain <[email protected]>
…igger

The changes of sensor_stream_trigger constrution inside
`SENSOR_DT_STREAM_IODEV` created divergence in parameter providing
method. sensor_chan_spec is now at the same state.
Also changed samples using it and documentation.

Signed-off-by: Logan Saint-Germain <[email protected]>
@Sokario Sokario force-pushed the drivers/sensors/sensor_async branch from a4f510a to 99560ad Compare October 23, 2025 14:25
@zephyrbot zephyrbot added the area: Samples Samples label Oct 23, 2025
@Sokario
Copy link
Contributor Author

Sokario commented Oct 23, 2025

Added two commits to address the following points:

  1. Provide the newly added chan_spec with a fallback default value of {SENSOR_CHAN_ALL, 0}.
  2. The modification introducing the fallback default value required an update to the parameter passed to the SENSOR_DT_STREAM_IODEV macro. Therefore, sensor_chan_spec must follow the same approach to maintain consistency between the two.

Of course the changes impact samples and documentation.
I will be updating the PR description accordingly.

@sonarqubecloud
Copy link

@Sokario
Copy link
Contributor Author

Sokario commented Oct 23, 2025

@MaureenHelm the CI is all green. Whenever you have a chance, your review would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Samples Samples area: Sensors Sensors size: XS A PR changing only a single line of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants